<%--
    Document   : index
    Created on : 12.02.2010, 22:48:51
    Author     : Morfant
--%>

<%@page import="stud.cp.user.valueobjects.DBObject"%>
<%@page import="stud.cp.user.valueobjects.DBObjectType"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"
        language="java"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <%@include file="/header.jsp"%>

    <script type="text/javascript">     
        function cancelEvent(e){
            if (!e)
                if (window.event) e = window.event;
            else return;
            if (e.cancelBubble != null) e.cancelBubble = true;
            if (e.stopPropagation) e.stopPropagation();
            if (e.preventDefault) e.preventDefault();
            if (window.event) e.returnValue = false;
            if (e.cancel != null) e.cancel = true;
        }
        function isActionCanBePerform(obj,e){
            var inputs = document.getElementsByTagName("input");
            var i=0;
            var isAtLeastOneCheckBoxSelect=false;
            var checkBoxValue=-1;
            while((i<inputs.length)&&(!isAtLeastOneCheckBoxSelect)){
                if(inputs[i].type=="checkbox"){
                    if(inputs[i].checked){
                        isAtLeastOneCheckBoxSelect=true;
                        checkBoxValue=inputs[i].value;
                    }
                }
                i++;
            }
            if(!isAtLeastOneCheckBoxSelect){
                alert("Выберите хотя бы один объект!");
                cancelEvent(e);
            }else{
                obj.href=obj.href+"<%="&" + PluginConst.OBJECT_ID + "="%>"+checkBoxValue;
            }
        }
        function checkOne(obj)
        {
            var grid = obj.parentNode.parentNode.parentNode;
            var inputs = grid.getElementsByTagName("input");
            for(var i=0;i<inputs.length;i++)
            {
                if (inputs[i].type =="checkbox")
                {
                    if(obj.checked && inputs[i] != obj && inputs[i].checked)
                    {
                        inputs[i].checked = false;
                    }
                }
            }
        }
    </script>

    <body>
        <div class="page">
            <%@include file="/cap.jsp"%>
            <div id="main">
                <%DBObjectType warehouseObjectType = (DBObjectType) request.getAttribute(PluginConst.OBJECT_TYPE);%>
                <h2>Список приходов.</h2>
                <table id="buttontable">
                    <tr>
                        <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%=response.encodeURL("warehouse-action.do")
                                            + "?"
                                            + PluginConst.SUBACTION
                                            + "="
                                            + PluginConst.GET_ADD_PAGE
                                            + "&"
                                            + PluginConst.OBJECT_TYPE_ID
                                            + "="
                                            + warehouseObjectType.getObject_type_id()%>">
                                            Добавить приход
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </th>
                        <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%=response.encodeURL("warehouse-action.do")
                                            + "?"
                                            + PluginConst.SUBACTION
                                            + "="
                                            + PluginConst.GET_EDIT_PAGE%>" 
                                           onclick="isActionCanBePerform(this,event)">
                                            Просмотреть данные прихода
                                    </li>
                                </ul>
                            </div>
                        </th>
                        <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%=response.encodeURL("warehouse-action.do")
                                            + "?"
                                            + PluginConst.SUBACTION
                                            + "="
                                            + PluginConst.GET_VIEW_PAGE%>">
                                            Просмотреть состояние склада
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </th>
                    </tr>

                </table>
                <%
                    List<DBObject> list = (List<DBObject>) request.getAttribute(PluginConst.OBJECT_LIST);
                    if ((list != null) && (list.size() > 0)) {
                %>
                <table>
                    <tr>
                        <th></th>
                        <th>Приход</th>
                    </tr>
                    <%
                        for (DBObject item : list) {
                    %>
                    <tr>
                        <td><input type="checkbox"
                                   name="<%=PluginConst.OBJECT_ID%>"
                                   value="<%=item.getObject_id()%>" onclick="checkOne(this)" />
                        </td>
                        <td>
                            <%=item.getName()%>
                        </td> 
                    </tr>
                    <%}%>
                </table>
                <%}%>

            </div>
        </div>
    </body>
</html>
